package com.geek.alert;

import com.geek.alert.beans.AlertRule;
import com.geek.alert.beans.ApiStatInfo;
import com.geek.alert.beans.MatchedRule;
import com.geek.alert.beans.Notification;
import com.geek.alert.domain.AlertProcessor;
import com.geek.alert.handler.ErrorAlertHandler;
import com.geek.alert.handler.TimeoutAlertHandler;
import com.geek.alert.handler.TpsAlertHandler;

public class Client {
    // 具体规则通过配置文件传入
    private static MatchedRule matchedRule;
    // 注入具体的通知实现类
    private static Notification notification;

    public static void main(String[] args) {
        ApiStatInfo apiStatInfo = ApiStatInfo.builder().build();

        // ...省略设置apiStatInfo数据值的代码
        // 改动三：设置tiemoutCount值

        AlertProcessor processor = AlertProcessor.builder()
                .notification(notification)
                .rule(new AlertRule(matchedRule)).build()
                .next(new TpsAlertHandler())
                .next(new ErrorAlertHandler())
                .next(new TimeoutAlertHandler());  // 改动四：添加到处理类中
        processor.process(apiStatInfo);
    }
}
